package org.xtense.rcp.editors.util;

import org.dom4j.Node;
import org.xtense.rcp.util.TreeEntry;

public class XmlEntry extends TreeEntry {
	public static int Element = 0;
	public static int Attribute = 1;
	
	private int type;
	private String value = "";
	private String path = "";
	
	private Node node;
	
	public Node getNode() {
		return node;
	}

	public void setNode(Node node) {
		this.node = node;
	}

	public void addChild(int index, XmlEntry entry) {
		entry.setParentEntry(this);
		getChildren().add(index, entry);
	}
	
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public XmlEntry(String name) {
		super(name);
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	public void remove() {
		XmlEntry parent = (XmlEntry) getParentEntry();
		if (parent != null) {
			parent.getChildren().remove(this);
		}
	}
	
	public void addBefore(XmlEntry en) {
		XmlEntry parent = (XmlEntry) getParentEntry();
		if (parent != null) {
			int index = parent.getChildren().indexOf(this);
			parent.getChildren().add(index, en);
		}
	}

	public void addAfter(XmlEntry en) {
		XmlEntry parent = (XmlEntry) getParentEntry();
		if (parent != null) {
			int index = parent.getChildren().indexOf(this);
			parent.getChildren().add(index + 1, en);
		}
	}
	
}
